package zjh.msg.service.Impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zjh.msg.entity.Msg;
import zjh.msg.entity.MsgDto;
import zjh.msg.entity.MsgVo;
import zjh.msg.mapper.MsgMapper;
import zjh.msg.service.MsgService;

import java.util.List;

@Service
public class MsgServiceImpl implements MsgService {

    @Autowired
    private MsgMapper msgMapper;

    @Override
    public List<MsgVo> pageList() {
        return msgMapper.pageList();
    }

    @Override
    public void save(MsgDto msgDto) {
        Msg msg = new Msg();
        msg.setNickname(msgDto.getBooks_Name());
        msg.setQq(msgDto.getBooks_Qq());
        msg.setText(msgDto.getBooks_Info());
        msg.setEmail(msgDto.getBooks_Mail());
        if (msgDto.getReplyId() != null) {
            msg.setReplyId(Integer.valueOf(msgDto.getReplyId()));
        }
        msgMapper.insert(msg);
    }

    @Override
    public void delete(Integer id) {
        msgMapper.deleteByPrimaryKey(id);
    }
}
